"""
定义接口对象层、类、方法
"""
import requests


class IhrmEmpAPI(object):
    # 添加员工
    @classmethod
    def add_emp(cls, req_header, req_body):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/sys/user",
                             headers=req_header,
                             json=req_body)
        return resp

    # 查询员工 - 注意参数顺序
    @classmethod
    def query_emp(cls, emp_id, req_header):
        resp = requests.get(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_header)
        return resp

    # 修改员工 - 注意参数顺序
    @classmethod
    def modify_emp(cls, emp_id, req_header, req_data):
        resp = requests.put(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_header,
                            json=req_data)
        return resp

    # 删除员工
    @classmethod
    def del_emp(cls, emp_id, req_header):
        resp = requests.delete(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                               headers=req_header)
        return resp


if __name__ == "" '__main__':
    # 准备请求头
    req_header = {"Authorization": "9f13c334-f193-47dc-ad9f-4fd7eb600542"}
    req_body = {
        "username": "user87655430",
        "mobile": "13947802950",
        "workNumber": "9527890aa"
    }
    resp = IhrmEmpAPI.add_emp(req_header, req_body)
    print("添加员工：", resp.json())

    resp = IhrmEmpAPI.query_emp("1516441184212467712", req_header)
    print("查询员工结果：", resp.json())

    modify_data = {"username": "萍子"}
    response = IhrmEmpAPI.modify_emp("1516441184212467712", req_header, modify_data)
    print("修改员工结果：", response.json())

    resp = IhrmEmpAPI.del_emp("1516441184212467712", req_header)
    print("删除结果：", resp.json())
